//
// Created by dave on 18-7-28.
//

#include <boost/asio/io_context.hpp>
#include <iostream>
#include <cassandra.h>
#include <glog/logging.h>
#include "tcp_server.h"

int main(int argc, char** argv) {
    google::InitGoogleLogging(argv[0]);
    google::SetStderrLogging(google::GLOG_INFO);

    if (argc != 2) {
        std::cerr << "Usage: " << argv[0] << " <port>" << std::endl;
        return 1;
    }

    unsigned short port = std::atoi(argv[1]);
    boost::asio::io_context serv_context;

//    CassCluster* cluster = cass_cluster_new();
//    CassSession* session = cass_session_new();
//    cass_cluster_set_contact_points(cluster, "127.0.0.1");
//    CassFuture* connect_future = cass_session_connect(session, cluster);
//    CassError rc = cass_future_error_code(connect_future);
//    printf("Connect result: %s\n", cass_error_desc(rc));

    tcp_server server(serv_context, port, nullptr /*session*/);
    server.start();
    boost::thread t1(boost::bind(&boost::asio::io_context::run, &serv_context));
    boost::thread t2(boost::bind(&boost::asio::io_context::run, &serv_context));
    boost::thread t3(boost::bind(&boost::asio::io_context::run, &serv_context));
    boost::thread t4(boost::bind(&boost::asio::io_context::run, &serv_context));
    boost::thread t5(boost::bind(&boost::asio::io_context::run, &serv_context));
    boost::thread t6(boost::bind(&boost::asio::io_context::run, &serv_context));

    t1.join();
    t2.join();
    t3.join();
    t4.join();
    t5.join();
    t6.join();
//    cass_future_free(connect_future);
//    cass_session_free(session);
//    cass_cluster_free(cluster);
    return 0;
}